﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using log4net;

namespace RecommenderSystem.misc
{
    public class Parser
    {
//        private static ILog logger = log4net.LogManager.GetLogger(typeof(Parser));


        public static ICollection<IDataRecord> getDataRecords(String fileName)
        {
            ICollection<IDataRecord> dataRecords = new LinkedList<IDataRecord>();
            ICollection<String> linesRecords = Reader.ReadAllLines( fileName );
            if (linesRecords == null)
            {
//                logger.Error("Failed to read data from file "+ fileName);
                return null;
            }
            foreach (String line in linesRecords)
            {
                String[] tokens = line.Split('\t');
                try
                {
                    IDataRecord dataRec = new ImplDataRecord();
                    dataRec.setData( Config.USER_ID, tokens[0]);
                    dataRec.setData( Config.ITEM_ID, tokens[1]);
                    dataRec.setData( Config.ITEM_RANK, tokens[2]);
                    dataRecords.Add( dataRec );
                }
                catch (IndexOutOfRangeException ){
//                    logger.Warn("failed to parse line: " + line);
                }

            }

            return dataRecords;
        }
    }
}
